import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({   // 注册并使用配置项
      imports: [
          'vue',
          'vue-router',
          {
            'naive-ui': [
              'useDialog',
              'useMessage',
              'useNotification',
              'useLoadingBar'
            ]
          }
      ],
      vueTemplate: true,
    }),
    Components({
      dirs: ['src/vcpns'],
      resolvers: [
        NaiveUiResolver(),
        (Component) => {
          if (Component.indexOf("Fa")===0) {
              return { importName: Component.substring(2), path: '@vicons/fa' }
          }
      }
      ]
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
